//
//  HLDiscussViewController.m
//  HLAerospace
//
//  Created by hulian-ios on 17/9/15.
//  Copyright © 2017年 hulian-LB. All rights reserved.
//

#import "HLDiscussViewController.h"
#import "HLDetailDiscussView.h"
#import "HLCourseDetail.h"
#import "HLStartQusetionViewController.h"
#import "HLCourseDiscuss.h"
#import "HLCommentListController.h"

@interface HLDiscussViewController ()<HLDetailDiscussViewDelegate>

@property (nonatomic ,weak) HLDetailDiscussView *discussView;

@end

@implementation HLDiscussViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.navigationItem.title = @"问题讨论";
    
    HLDetailDiscussView *discussView = [[HLDetailDiscussView alloc]initWithFrame:self.view.bounds];
    discussView.courseID = self.courseID;
    discussView.delegate = self;
    [self.view addSubview:discussView];
    self.discussView = discussView;
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(userAskQuestionSuccess) name:kHLUserAskQuestionSuccessNotifacation object:nil];
}

- (void)detailDiscussView:(HLDetailDiscussView *)detailDiscussView didClickAskQuestion:(UIButton *)button
{
    HLStartQusetionViewController *start = [HLStartQusetionViewController new];
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:start];
    start.question_course_id = self.courseID;
    [self presentViewController:nav animated:YES completion:nil];
}

- (void)detailDiscussView:(HLDetailDiscussView *)detailDiscussView questionListDidSelecte:(HLCourseDiscuss *)course
{
    HLCommentListController *comment = [HLCommentListController new];
    comment.courseDiscuss = course;
    [self.navigationController pushViewController:comment animated:YES];
}

- (void)userAskQuestionSuccess
{
    [self.discussView reloadData];
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

@end
